﻿/// <reference path="../libraries/jquery-1.6.4.js" />
/// <reference path="../libraries/jquery.mobile-1.4.0.js" />
/// <reference path="../libraries/q.js" />

var HttpRequester = (function () {

    var ajaxRequestPromise = function (url, type, data) {

        var deffered = Q.defer();

        if (data) {
            data = JSON.stringify(data);
        }

        $.ajax({
            url: url,
            type: type,
            data: data,
            contentType: "application/json",
            success: function (responseData) {
                deffered.resolve(responseData);
            },
            error: function (errorData) {
                deffered.reject(errorData);
            }
        });

        return deffered.promise;
    }

    var ajaxGetPromise = function (url) {
        return ajaxRequestPromise(url, "get");
    }

    var ajaxPostPromise = function (url, data) {
        return ajaxRequestPromise(url, "post", data);
    }

    return {
        get : ajaxGetPromise,
        post : ajaxPostPromise
    }
}())
